package com.langsin.service.impl;

import com.langsin.dao.ProductDao;
import com.langsin.dao.impl.ProductDaoImpl;
import com.langsin.service.ProductService;
import com.langsin.vo.Product;

import java.util.List;

public class ProductServiceImpl implements ProductService{

    private ProductDao productDao = new ProductDaoImpl();

    @Override
    public List<Product> queryAll() {
        List<Product> list = null;
        try {
            list = productDao.queryAll();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return list;
    }

    @Override
    public List<Product> queryListByName(String pname, String pcode) {
        List<Product> list = null;
        pname = "%"+pname+"%";
        System.out.println("pname:"+pname);
        try {
            list = productDao.queryListByName(pname,pcode);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return list;
    }

    @Override
    public int insertProduct(Product product) {
        try {
           return productDao.insertProduct(product);
        } catch (Exception e) {
            e.printStackTrace();
            return 0;
        }
    }

    @Override
    public Product queryProductById(String prodId) {
        Product prod = null;
        try {
            prod = productDao.queryProductById(prodId);
            return prod;
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }

    @Override
    public int updateProduct(Product product) {
        try {
            return productDao.updateProduct(product);
        } catch (Exception e) {
            e.printStackTrace();
            return 0;
        }
    }
}
